

INCLUDE_DIR=

#子目录的Makefile直接读取其子目录就行
SUBDIRS=$(shell ls -l | grep ^d | awk '{print $$9}')

C_SOURCES = $(wildcard  *.c)
ASM_SOURCES = $(wildcard *.asm)

# Create a list of  object  files  to build , simple  by  replacing# the  ’.c’
# extension  of  filenames  in  C_SOURCES  with  ’.o’
OBJ_O = $(patsubst %.c, %.o, ${C_SOURCES})
OBJ_O += $(patsubst %.asm, %.o, ${ASM_SOURCES})
OBJ = $(addprefix ${OBJS_DIR}/, ${OBJ_O})


all : BUILD

BUILD: ${OBJ} $(SUBDIRS)

$(OBJS_DIR):
	make -C $@


$(OBJS_DIR)/%.o : %.c ${INCLUDE_DIR}
	${CC} ${INCLUDE_DIR} ${CFLAGS} $< -o $@

$(OBJS_DIR)/%.o : %.cpp ${INCLUDE_DIR}
	${CC} ${INCLUDE_DIR} ${CFLAGS} $< -o $@


$(OBJS_DIR)/%.o: %.asm
	${NASM} $< -f elf32 -o $@


$(BIN_DIR)/%.bin: %.asm
	${NASM} $< -f bin -o $@